/**
 * 
 */
package com.redpixy.monit.schedule;

import org.dom4j.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.redpixy.monit.common.Address;
import com.redpixy.monit.common.param.CheckAddressParam;
import com.redpixy.monit.common.param.MailParam;
import com.redpixy.monit.common.util.StrUtil;
import com.redpixy.monit.mail.MailSender;

/**
 * @author admin
 *
 */
public class MonitDailyReport implements Runnable{
	private static final Logger log = LoggerFactory
	.getLogger(MonitDailyReport.class);
	@Override
	public void run() {
		log.info("----->发送运行日报......");
		String title = "服务器运行日报";
		String context = "所有服务运行正常，监控服务运行正常。<br><br><hr>";
		if(MailParam.ERRORADDRESS.size()>0){
		context = "";
			for (String key : MailParam.ERRORADDRESS.keySet()) {
				if(!StrUtil.isEmptyObj(MailParam.ERRORADDRESS.get(key)))
				{
					Address add = MailParam.ERRORADDRESS.get(key);
					context+= "【运行异常】  "+add.getName() +",服务地址："+add.getFullURL()+"<br>";
				}
				
			}
			context+="<br><hr>";
		}

		for (Address add : MailParam.CHECK_ADRESS) {
			String url = add.getFullURL();
			if(!MailParam.ERRORADDRESS.containsKey(url)){
				context+= "【运行正常】 "+add.getName()+",服务地址："+url +"<br>";
			}
		}
		
		context+="<hr>";
		context+="<br> 监控服务启动时间:"+ MailParam.STARTTIME;
		context+="<br> <br> <br> <br>";
		MailSender.sendMail(title, context, MailParam.RECEIVE);
		log.info("----->发送运行日报结束.....");
	}

}
